﻿using System;
using System.Diagnostics;
using Client.Properties;

namespace Client.UIHelper
{
    public class Logger
    {
        private static bool bSetup;

        public Logger(string path, string fileName)
        {
            if (!bSetup)
            {
                try
                {
                    string logPath = path;

                    bool log = false;

                    //log = Convert.ToBoolean(ConfigurationSettings.AppSettings["loggingEnabled"]);
                    log = true;

                    if (log)
                    {
                        // Setup logging listener
                        Trace.Listeners.Add(new TextWriterTraceListener(logPath + "\\" + fileName));
                        Trace.AutoFlush = true;
                    }
                }

                catch (Exception ex)
                {
                    // Do nothing, logging will not be enabled
                }

                bSetup = true;
            }
        }

        public bool AlreadySetup
        {
            get { return bSetup; }
        }

        public static void Log(string s)
        {
            if (Settings.Default.LoggingEnabled)
            {
                Trace.WriteLine(DateTime.Now + " : " + s);
            }
        }
    }
}